<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>提交订单_填写收货地址</title>
    <script type="text/javascript" src="__PUBLIC__/Js/home/jquery-1.11.3.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Js/layer/layer.js"></script>
    <script>
        //要写在user_common.js调用之前     因tp框架中定义的常量，在外部调用的js中不能被解析
        var tp_defined = {'url': '__URL__', 'self': '__SELF__'};
    </script>
    <script type="text/javascript" src="__PUBLIC__/Js/home/user_common.js"></script>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/home/sureOrder.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/home/addAddress.css">
    <script type="text/javascript">
        //将获取到的地址信息写入收货信息表中
        function insertShippingAddress(address_data) {
            $('.shipping_address input').attr('value', address_data.id);
            $('.shipping_address input').prop('checked', true);
            $('.shipping_address .name').html(address_data.name);
            $('.shipping_address .address').html(address_data.address);
            $('.shipping_address .mobile').html(address_data.mobile);
            $('.shipping_address .postcode').html(address_data.postcode);
            $('.shipping_address').removeAttr('style');
        }
        //获取默认收货地址
        function getDefaultAddress() {
            layer.load(1);
            $.post(
                    '__URL__/orderAddressAction',
                    {action: 'getDefaultAddress'},
                    function (data) {
                        layer.closeAll('loading');
                        //判断是否有默认地址
                        if (data['status'] == 1) {
                            $('.noDefaultAddress').attr('style', 'display:none');
                            $('.shipping_address').removeAttr('style');
                            var address_data = data['content'];
                            $('.shipping_address label').html('使用默认地址');
                            address_data.address = address_data.province + address_data.city + address_data.district + address_data.street;
                            insertShippingAddress(address_data);
                        } else {
                            $('.noDefaultAddress').removeAttr('style');
                            $('.shipping_address').attr('style', 'display:none');
                        }
                    },
                    'json'
            );
        }
        //页面加载时，自动调用获取默认地址
        getDefaultAddress();
        //给每个获取到的其他地址的单选框加操作
        function otherAddress(address_id) {
            //获取选择的收货地址的信息
            var input = $('.other_address input[value=' + address_id + ']');
            var td = input.parents('tr');
            var address_data = {
                'id': input.val(),
                'name': td.children('.name').text(),
                'address': td.children('.address').text(),
                'mobile': td.children('.mobile').text(),
                'postcode': td.children('.postcode').text()
            };
            //将获得的收货信息填写到收货信息表中
            $('.shipping_address label').html('使用其他地址');
            insertShippingAddress(address_data);
            $('.other_address').attr('style', 'display:none');
        }
        $(function () {
            //调出、隐藏地址栏
            //var defaultAddress = $('.default_address');
            var noDefaultAddress = $('.noDefaultAddress');
            var shippingAddress = $('.shipping_address');
            var otherAddress = $('.other_address');
            var addAddress = $('.shop_adress-add');
            //使用默认地址按钮
            $('.use_default_address').click(function () {
                otherAddress.attr('style', 'display:none');
                addAddress.attr('style', 'display:none');
                shippingAddress.removeAttr('style');
                getDefaultAddress();
            });
            //选择其他地址
            $('.use_other_address').click(function () {
                noDefaultAddress.attr('style', 'display:none');
                shippingAddress.attr('style', 'display:none');
                otherAddress.removeAttr('style');
                addAddress.attr('style', 'display:none');
                $('.other_address-table tr:gt(0)').remove();
                //获取默认收货地址
                layer.load(1);
                $.ajax({
                    //async: false, //使用同步请求
                    type: 'POST',
                    url: '__URL__/orderAddressAction',
                    data: {action: 'getOtherAddress'},
                    success: function (data) {
                        layer.closeAll('loading');
                        $('.other_address-table-title').after(data['content']);
                    },
                    dataType: 'json'
                });
            });
            //填写地址
            $('.member_adress-addtop').click(function () {
                noDefaultAddress.attr('style', 'display:none');
                shippingAddress.attr('style', 'display:none');
                otherAddress.attr('style', 'display:none');
                addAddress.removeAttr('style');
            });
            //保存或提取填写的收货信息
            $('.shop_adress-save').click(function () {
                var address_data = check();
                if (address_data == false) {
                    return;     //结果不正确，则不提交
                }
                //因在获取填写信息时已经获取了是否保存为默认地址
                //传递数据，并写入数据库中
                layer.load(1);
                $.post(
                        '__URL__/myAddress',
                        address_data,
                        function (data) {
                            layer.closeAll('loading');  //关闭加载层
                            if (data['status'] == 1) {
                                layer.msg(data['content'], {time: 1000});
                                //将获得的收货信息填写到收货信息表中
                                $('.shipping_address label').html('使用新添加地址');
                                address_data.id = data['address_id'];
                                address_data.address = address_data.province + address_data.city + address_data.district + address_data.street;
                                insertShippingAddress(address_data);
                                addAddress.attr('style', 'display:none');
                            } else {
                                layer.alert(data['content']);
                            }
                        }
                );
            });
            //提交订单
            $('.shop_adress-tjdd').click(function () {
                if ($(".shop_cort-adress input[name='address']:checked").length < 1) {
                    layer.alert('请选择或填写收货地址！');
                } else if ($('.shop_adressqr-of tr:gt(0)').length < 1) {
                    layer.alert('你没有要提交的商品，请选择购买的商品！');
                } else {
                    $('#submitForm').submit();
                }
            });
        });
    </script>
</head>
<body>
<!--全部背景-->
<div class="all-thing">
    <!--中间内容-->
    <div class="tcmain">
        <!--引入购物车头部文件-->
        <include file="Common/cart_header"/>
        <!--导航条-->
        <div id="ctl00_showNav" class="shop_nav shop_nav-dd"></div>
        <!--导航条end-->
        <!--内容-->
        <div class="shop_cort">
            <!--左边-->
            <div class="shop_cort-left fl">
                <div class="shop_cort-left-title">
                    <h3>收货人信息</h3>
                    <span class="use_default_address">使用默认地址</span>
                    <span class="use_other_address">选择其他地址</span>
                    <span class="member_adress-addtop">填写并使用新地址</span>
                </div>
                <!--填写地址信息-->
                <div class="shop_cort-adress">

                    <!--新加地址-->
                    <div class="shop_adress-add" style="display: none">
                        <!--三级联动 start-->
                        <div class="shop_adress-Toadd" id="addresses" style="">
                            <label><em>*</em>地&nbsp;&nbsp;区：</label>
                            <select id="province">
                                <option value="-1">请选择省份</option>
                            </select>
                            <span>市：</span>
                            <select id="city">
                                <option value="-1">请选择城市</option>
                            </select>
                            <span>县：</span>
                            <select id="district">
                                <option value="-1">请选择区县</option>
                            </select>

                            <span id="addid">
                                <i class="writer_wrong"></i>
                                <em class="writer_word" id="addwrong"></em>
                            </span>
                        </div>
                        <!--详细地址-->
                        <div class="shop_adress-Toadd" id="detailadd">
                            <label class="adress-Toadd_label"><em>*</em>详细地址：</label><textarea maxlength="30" id="street"></textarea>
                            <span id="streeid">
                                <i class="writer_wrong"></i>
                                <em class="writer_word" id="strwrong"></em>
                            </span>
                        </div>
                        <!--收货人-->
                        <div class="shop_adress-Toadd" id="pname">
                            <label><em>*</em>收货人：</label><input value="" maxlength="10" id="addressName" class="true_name" type="text">
                            <span id="shrid">
                                <i class="writer_wrong"></i>
                                <em class="writer_word" id="shrwrong"></em>
                            </span>
                        </div>
                        <!--邮编-->
                        <div class="shop_adress-Toadd" id="post">
                            <label><em>*</em>邮政编码：</label><input value="" maxlength="6" id="postcode" class="true_number" type="text">
                            <span id="postid">
                                <i class="writer_wrong"></i>
                                <em class="writer_word" id="postwrong"></em>
                            </span>
                        </div>
                        <!--手机号-->
                        <div class="shop_adress-Toadd" id="lx" style="">
                            <label><em>*</em>手机号码：</label><input value="" maxlength="11" id="mobile" type="text">
                                <span id="telid">
                                    <i class="writer_wrong"></i>
                                    <em class="writer_word" id="telwrong"></em>
                                </span>
                        </div>
                        <div class="shop_adress-sp">
                            <input id="cbDefaultAddress" type="checkbox" name="cbDefaultAddress">
                            <label class="add_adress-splabel cbDefaultAddress" for="cbDefaultAddress">设为默认地址</label>
                        </div>
                        <div class="shop_adress-save">
                            <div class="bt1"><span class="save">保存并使用此地址</span></div>
                        </div>
                    </div>
                    <!--新加地址end-->
                    <!--其他收货地址 start-->
                    <div class="other_address" style="display: none">
                        <table class="other_address-table">
                            <tr class="other_address-table-title">
                                <td class="other_address-td0">选择</td>
                                <td class="other_address-td1">收件人姓名</td>
                                <td class="other_address-td2">详细地址</td>
                                <td class="other_address-td3">联系方式</td>
                                <td class="other_address-td4">邮政编码</td>
                            </tr>
                        </table>
                    </div>
                    <!--其他收货地址 end-->
                    <form method="post" action="__URL__/submitOrder" id="submitForm">
                        <!--默认地址信息 start-->
                        <div class="noDefaultAddress" style="display: none">没有默认地址，请选择或填写收货信息！</div>
                        <div class="shipping_address" style="display: none">
                            <input type="radio" value="" id="" name="address">
                            <label for="">########</label>
                            <table class="shipping_address-table">
                                <tr>
                                    <th>收货人：</th>
                                    <td class="name"></td>
                                </tr>
                                <tr>
                                    <th>收货地址：</th>
                                    <td class="address"></td>
                                </tr>
                                <tr>
                                    <th>联系方式：</th>
                                    <td class="mobile"></td>
                                </tr>
                                <tr>
                                    <th>邮编：</th>
                                    <td class="postcode"></td>
                                </tr>
                            </table>
                        </div>
                        <!--默认地址信息 end-->
                        <div class="shop_adress-qr">
                            <div class="shop_adressqr-top">
                                <a href="__URL__/cart" class="fr">返回修改购物车&gt;&gt;</a>
                                <span>确认订单信息</span>
                                <!--<i>提示：专属订制产品，需要相关证书认证时间。建议尽快提交。</i>-->
                            </div>
                            <!--订单-->
                            <table class="shop_adressqr-of" border="0" cellpadding="0" cellspacing="0">
                                <tr class="shop_adressqr-first">
                                    <td class="shop_adress-shoop">商 品</td>
                                    <td class="shop_adress-cz">材 质</td>
                                    <!--<td class="shop_adress-sc">手寸/尺寸</td>
                                    <td class="shop_adress-kz">刻 字</td>-->
                                    <td class="shop_adress-pirce">单价(￥)</td>
                                    <td class="shop_adress-num">数量</td>
                                    <td class="shop_adress-total">价 格(￥)</td>
                                </tr>
                                <foreach name="checked_data" item="v">
                                    <tr class="shop_adressqr-sec">
                                        <input type="hidden" name="checked_cart_id[]" value="{$v['id']}">
                                        <td class="shop_adress-shoop"><a href="__MODULE__/Goods/details/id/{$v['goods_detail_id']}">{$v['goods_style']}{$v['goods_name']}</a></td>
                                        <td class="shop_adress-cz">
                                            <switch name="v['material']">
                                                <case value="0">白18K金</case>
                                                <case value="1">PT950</case>
                                            </switch>
                                        </td>
                                        <!--<td class="shop_adress-sc">{$v['size']}</td>
                                        <td class="shop_adress-kz">{$v['carve']}</td>-->
                                        <td class="shop_adress-pirce">{$v['price']}</td>
                                        <td class="shop_adress-num">{$v['num']}</td>
                                        <td class="shop_adress-total"><span style="font-family: 微软雅黑;">{$v['price']*$v['num']}</span></td>
                                    </tr>
                                </foreach>
                            </table>
                            <!--订单end-->
                            <!--总计-->
                            <div class="shop_adress-zj">
                                <div class="fl">
                                    <span> 总计</span>
                                </div>
                                <div class="fr">
                                    <i class="good_num">0</i>
                                    <span>件商品</span>
                                    <span>应付金额：</span>
                                    <i class="fw_bold" style="font-family: 微软雅黑;">￥0</i>
                                </div>
                            </div>
                            <script>
                                $(function () {
                                    var goods = $('.shop_adressqr-of tr:gt(0)');
                                    var good_num = 0;
                                    var total = 0;
                                    for (var i = 0; i < goods.length; i++) {
                                        good_num += parseInt(goods.eq(i).children('.shop_adress-num').text());
                                        total += parseInt(goods.eq(i).children('.shop_adress-total').text());
                                    }
                                    $('.good_num').html(good_num);
                                    $('.fw_bold').html('￥' + total);
                                });
                            </script>
                            <!--总计-->
                            <!--最后一块-->
                            <div class="shop_adress-last">
                                <div class="shop_adress-ddbz fl">
                                    <p>订单备注</p>
                                    <textarea name="ordernote" class="shop_adress-text" placeholder="此处请勿填写有关支付方面的信息,留言请在50字以内。"></textarea>
                                </div>
                                <div class="shop_adress-tjdd fr">
                                    <input type="hidden" value="{$de}">
                                    <div class="bt1 fr"><span>立即提交订单</span></div>
                                </div>
                            </div>
                            <!--最后一块end-->
                        </div>
                    </form>
                </div>
                <!--填写地址信息end-->
            </div>
            <!--左边end-->
            <!--引入购物车右侧文件-->
            <include file="Common/cart_right"/>
        </div>
        <!--内容end-->
        <!--引入购物车底部文件-->
        <include file="Common/cart_footer"/>
    </div>
    <!--全部背景end-->
</div>
</body>
</html>
